using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TradeFlow.Server.Service;
using TradeFlow.Server.Dto;
using TradeFlow.Server.Models;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using TradeFlow.Server.Language;
using System.Reflection;

namespace TradeFlow.Web.Controllers
{
    /// <summary>
    /// 业务单表体控制器
    /// </summary>
    [Authorize]
    public class JxBillListController : Controller
    {
        private readonly JxBillListService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public JxBillListController(JxBillListService service)
        {
            _service = service;
        }

        /// <summary>
        /// 查询业务单表体分页列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetPages([FromBody] JxBillListPageParam param)
        {
            var result = await _service.GetPagesAsync(param);
            return Json(result);
        }

        /// <summary>
        /// 获取所有业务单表体列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetList()
        {
            var result = await _service.GetListAsync();
            return Json(result);
        }

        /// <summary>
        /// 根据表头ID获取表体列表
        /// </summary>
        /// <param name="headId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetByHeadId(long headId)
        {
            var result = await _service.GetByHeadIdAsync(headId);
            return Json(result);
        }

        /// <summary>
        /// 增加业务单表体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add([FromBody] JxBillList entity)
        {
            var result = await _service.AddAsync(entity);
            return Json(result);
        }

        /// <summary>
        /// 批量增加业务单表体
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BatchAdd([FromBody] List<JxBillList> entities)
        {
            var result = await _service.BatchAddAsync(entities);
            return Json(result);
        }

        /// <summary>
        /// 更新业务单表体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update([FromBody] JxBillList entity)
        {
            var result = await _service.UpdateAsync(entity);
            return Json(result);
        }

        /// <summary>
        /// 删除业务单表体
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> Delete([FromBody] List<long> ids)
        {
            var result = await _service.DeleteAsync(ids);
            return Json(result);
        }
    }
}